import 'package:flutter/material.dart';
import 'package:ruitmentapp/core/extension/int_extension.dart';
import 'package:ruitmentapp/personnel/model/zj_home_model.dart';
import 'package:ruitmentapp/core/shared/size_fit.dart';
import 'package:ruitmentapp/personnel/model/zj_job_details_model.dart';

final cardRadius = 5.px;

class ZJHomeContentJobdescriptionCard extends StatelessWidget {

  final ZJJobDetailsModel _detailsModel;
  ZJHomeContentJobdescriptionCard(this._detailsModel);

  @override
  Widget build(BuildContext context) {
    return Container(
      child: buildTitleCard(context),
    );
  }

  Widget buildTitleCard(BuildContext context) {
    return Card(
      margin: EdgeInsets.only(left: 20.px, right: 20.px, bottom: 10.px),
      elevation: 0.0,
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(cardRadius)),
      child: Column(
        children: <Widget>[
          buildPushTitleInfo(context),
          buildLineInfo(),
          buildBasicInfo(context),
          buildOperationInfo(context),
        ],
      ),
    );
  }

  Widget buildLineInfo() {
    return SizedBox(
        width: ZJSizeFit.screenWidth - 70.px,
        height: 1.px,
        child: Container(
          color: const Color(0xFFF3F5F7),
        )
    );
  }

  Widget buildPushTitleInfo(BuildContext context) {
    return Row(
      children: const [
        Expanded(child:
          Padding(
            padding: EdgeInsets.only(top: 10, left: 15, right: 15,bottom: 10),
            child: Text('职位描述',
                textAlign:TextAlign.left,
                style: TextStyle(
                    color: Color(0xFF3F4756),
                    fontSize: 16,
                    fontWeight: FontWeight.bold)
            ),
          ),
        ),
      ],
    );
  }

  Widget buildBasicInfo(BuildContext context) {

    List <Widget> textArray = [];
    for(LabelList item in _detailsModel.publishDetail.labelList){
      textArray.add(
          Card(
            elevation: 0.0,//设置阴影，即card在z轴的距离，数字越大阴影越重
            color: const Color(0xFFF3F5F7),//设置颜色，数字为颜色饱和度
            shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(3.0))),
            child: Container(
                padding: const EdgeInsets.only(left: 10, top: 3, bottom: 3, right: 10),
                child: Text(item.name, style: const TextStyle(color: Color(0xFF77809E),fontSize: 12))
            ),
          )
      );
    }

    return _detailsModel.publishDetail.labelList.isNotEmpty ? Container(
      color: Colors.white,
      width: MediaQuery.of(context).size.width - 70,
      height: 40,
      margin: const EdgeInsets.only(top: 5),
      child: SingleChildScrollView(
        physics: const BouncingScrollPhysics(),
        scrollDirection: Axis.horizontal,
        child: Center(
          child: Row(
            children: textArray,
          ),
        ),
      ),
    ):Container();
  }

  Widget buildOperationInfo(BuildContext context) {
    return Row(
        children: <Widget>[
          Expanded(child:
              Padding(
                padding: const EdgeInsets.only(left: 15, right: 15,bottom: 15, top: 10),
                child: Text(_detailsModel.publishDetail.describe,
                    style: const TextStyle(color: Color(0xFF77809E), fontSize: 14)),
              ),
          ),
        ]
    );
  }
}
